<?php


namespace app\admin\controller;


use app\common\controller\Backend;

class Adproject extends Backend
{
    /**
     * Ads模型对象
     * @var \app\admin\model\Adzone
     */
    protected $model = null;

    protected $relationSearch = true;

    protected $searchFields = 'user.mobile|user.username|user.nickname';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Adproject();

    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        $zone_id = $this->request->param('zone_id', '', 'intval');
        $map = [];
        if ($zone_id) {
            $map['zone_id'] = $zone_id;
        }
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->with('user')
                ->where($where)
                ->where($map)
                ->order($sort, $order)
                ->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }
}